<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AdminLTE 2 | Starter</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" href="/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="/Ionicons/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. We have chosen the skin-blue for this starter
        page. However, you can choose any other skin. Make sure you
        apply the skin class to the body tag so the changes take effect. -->
    <link rel="stylesheet" href="/dist/css/skins/skin-blue.min.css">


    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

    <!-- Google Font -->
    <link rel="stylesheet"
        href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<!--
BODY TAG OPTIONS:
=================
Apply one or more of the following classes to get the
desired effect
|---------------------------------------------------------|
| SKINS         | skin-blue                               |
|               | skin-black                              |
|               | skin-purple                             |
|               | skin-yellow                             |
|               | skin-red                                |
|               | skin-green                              |
|---------------------------------------------------------|
|LAYOUT OPTIONS | fixed                                   |
|               | layout-boxed                            |
|               | layout-top-nav                          |
|               | sidebar-collapse                        |
|               | sidebar-mini                            |
|---------------------------------------------------------|
-->

<body class="hold-transition skin-blue sidebar-mini">
    <div class="wrapper">

        <!-- Main Header -->
        <%- include("./header.ejs") %>
        <!-- Left side column. contains the logo and sidebar -->

        <%- include("./menus.ejs") %>

        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <h1>
                    商品管理
                    <!-- Page Header
          <small>Optional description</small> -->
                </h1>
                <ol class="breadcrumb">
                    <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
                    <li class="active">Here</li>
                </ol>
            </section>

            <!-- Main content -->
            <section class="content container-fluid">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header">
                                <h3 class="box-title">
                                    <a href="/pro/add">
                                        <button class="btn btn-info btn-lg">添加商品</button>
                                    </a>
                                    <a href="/pro/sort?type=price&num=1">
                                        <button class="btn btn-warning btn-xs">价格升序</button>
                                    </a>
                                    <a href="/pro/sort?type=price&num=-1">
                                        <button class="btn btn-warning btn-xs">价格降序</button>
                                    </a>
                                    <a href="/pro/sort?type=sales&num=1">
                                        <button class="btn btn-warning btn-xs">销量升序</button>
                                    </a>
                                    <a href="/pro/sort?type=sales&num=-1">
                                        <button class="btn btn-warning btn-xs">销量降序</button>
                                    </a>
                                    <a href="/pro/sort?type=stock&num=1">
                                        <button class="btn btn-warning btn-xs">库存升序</button>
                                    </a>
                                    <a href="/pro/sort?type=stock&num=-1">
                                        <button class="btn btn-warning btn-xs">库存降序</button>
                                    </a>
                                </h3>
                                <div class="box-tools">
                                    <div class="input-group input-group-sm" style="width: 150px;">
                                        <input type="text" name="table_search" class="form-control pull-right"
                                            placeholder="Search" id="searchText" onchange=search()>
                                        <div class="input-group-btn">
                                            <button class="btn btn-default" id="btn" onclick=search()>
                                                <i class="fa fa-search"></i>
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- /.box-header -->
                            <div class="box-body table-responsive no-padding">
                                <table class="table table-hover">
                                    <thead>
                                        <tr>
                                            <th width="10%">商品序号</th>
                                            <th width="30%">商品名称</th>
                                            <th width="20%">商品图片</th>
                                            <th width="10%">商品价格</th>
                                            <th width="10%">商品销量</th>
                                            <th width="10%">商品库存</th>
                                            <th width="10%">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <% for (let i = 0; i < data.length; i++) { %>
                                        <tr>
                                            <td><%= limit * (count - 1) + i + 1 %></td>
                                            <td><%= data[i].proname %></td>
                                            <td>
                                                <img src="<%= data[i].proimg %>" alt=""
                                                    style="width:100px; height: 60px;">
                                            </td>
                                            <td><%= data[i].price %></td>
                                            <td><%= data[i].sales %></td>
                                            <td><%= data[i].stock %></td>
                                            <td>
                                                <a href="/pro/update?proid=<%= data[i].proid %>">
                                                    <button type="button" class="btn btn-warning">
                                                        <i class="fa fa-gear"></i>
                                                    </button>
                                                </a>
                                                <button type="button" class="btn btn-danger" data-toggle="modal"
                                                    data-target="#exampleModal" data-whatever="<%= data[i].proid %>">
                                                    <i class="fa fa-trash"></i>
                                                </button>
                                            </td>
                                        </tr>
                                        <% } %>
                                    </tbody>
                                </table>
                                <!-- 模态框 -->
                                <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog"
                                    aria-labelledby="exampleModalLabel" aria-hidden="true">
                                    <div class="modal-dialog">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal"
                                                    aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                            </div>
                                            <div class="modal-body">
                                                <p>您确定要删除此商品吗？</p>
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-secondary"
                                                    data-dismiss="modal">取消</button>
                                                <button type="button" class="btn btn-primary" id="js_del">确定</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <ul class="pagination d-block">
                            <li class="paginate_button previous <%= count === 1 ? 'disabled' : '' %>"
                                id="example2_previous">
                                <a href="/pro?count=<%= count > 1 ? count - 1 : 1 %>" aria-controls="example2"
                                    data-dt-idx="0" tabindex="0">上一页</a>
                            </li>
                            <% for (let i = 0; i < counts; i++) {%>
                            <li class="paginate_button <%= count === i + 1 ? 'active' : '' %>">
                                <a href="/pro?count=<%= i + 1 %>" aria-controls="example2" data-dt-idx="1"
                                    tabindex="0"><%= i + 1 %></a>
                            </li>
                            <% } %>
                            <li class="paginate_button next <%= count === counts ? 'disabled' : '' %>"
                                id="example2_next">
                                <a href="/pro?count=<%= count < counts ? count + 1 : counts %>" aria-controls="example2"
                                    data-dt-idx="7" tabindex="0">下一页</a>
                            </li>
                        </ul>
                        <!-- /.box -->
                    </div>
                </div>
            </section>
            <!-- /.content -->
        </div>
        <!-- /.content-wrapper -->

        <!-- Main Footer -->

        <%- include("./footer.ejs") %>

        <!-- Control Sidebar -->
        <%- include("./siderbar.ejs") %>
        <!-- /.control-sidebar -->
        <!-- Add the sidebar's background. This div must be placed
  immediately after the control sidebar -->
        <div class="control-sidebar-bg"></div>
    </div>
    <!-- jQuery 3 -->
    <script src="/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap 3.3.7 -->
    <script src="/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- AdminLTE App -->
    <script src="/dist/js/adminlte.min.js"></script>
    <!-- Optionally, you can add Slimscroll and FastClick plugins.
     Both of these plugins are recommended to enhance the
     user experience. -->
    <script>
        function search() {
            let searchText = $("#searchText").val();
            window.location.href = '/pro/search?searchText=' + searchText;
        }
        // 模态框
        $('#exampleModal').on('show.bs.modal', function (event) {
            let button = $(event.relatedTarget);
            let recipient = button.data('whatever');
            $("#js_del").on("click", function () {
                window.location.assign("/pro/deleteAction?proid=" + recipient);
            })
        })
    </script>
</body>

</html>